<?php

namespace App\Model;

use PhalApi\Model\NotORMModel as NotORM;


class Goods extends NotORM
{
    public function getGoodsInfo()
    {
        return $this->getORM()->fetchAll();
    }

    public function getGoodInfo($good_id)
    {
        return $this->getORM()->where('id', $good_id)->fetchOne();
    }

    public function getGoodInfoByTypeName($good_type)
    {
        return $this->getORM()->where('typeName', $good_type)->fetchAll();
    }

    public function insertGoodsInfo($good_name, $good_price, $good_typeName, $good_star, $good_pubdate, $good_picture, $good_intro)
    {
        $data = array('name' => $good_name, 'price' => $good_price, 'typeName' => $good_typeName, 'star' => $good_star, 'pubdate' => $good_pubdate, 'picture' => $good_picture, 'intro' => $good_intro, 'flag' => 1);
        $orm = $this->getORM();
        $orm->insert($data);
        return $orm->insert_id();
    }

    public function updateGoodsInfo($good_id, $good_name, $good_price, $good_typeName, $good_pubdate, $good_picture, $good_intro)
    {
        $data = array('name' => $good_name, 'price' => $good_price, 'typeName' => $good_typeName, 'pubdate' => $good_pubdate, 'picture' => $good_picture, 'intro' => $good_intro);
        return $this->getORM()->where('id', $good_id)->update($data);
    }

    public function deleteGoodsInfo($good_id)
    {
        return $this->getORM()->where('id', $good_id)->delete();
    }

    public function likeQueryByGoodsName($like_goodName){
        return $this->getORM()->where('name LIKE ?', "%$like_goodName%")->fetchAll();

    }
    public function likeQueryByGoodsDate($like_goodDate){
        return $this->getORM()->where('pubdate LIKE ?', "%$like_goodDate%")->fetchAll();

    }
}